package com.lk.service;

import com.lk.beans.User;
import com.lk.dao.UserDao;
import com.lk.utils.MD5Util;
import com.lk.vo.ResultInfo;

public class UserService {
    private UserDao userDao=new UserDao();

    public ResultInfo<User> userLogin(String userName,String userpwd){
        ResultInfo<User> resultInfo=new ResultInfo<>();
        //判断用户名和密码是否为空
        if(userName==null||userName.trim()==""){
            resultInfo.setCode(0);
            resultInfo.setMsg("用户名不能为空");
            return resultInfo;
        }
        if(userpwd==null||userpwd.trim()==""){
            resultInfo.setCode(0);
            resultInfo.setMsg("密码不能为空");
            return resultInfo;
        }
        //通过用户名查询用户
        User user= userDao.searchByName(userName);
        if(user==null){
            resultInfo.setCode(0);
            resultInfo.setMsg("用户不存在");
            return resultInfo;
        }
        userpwd = MD5Util.code(userpwd);
        //将密码加密后比较是否相同
        if(!userpwd.equals(user.getUpwd())){
            resultInfo.setCode(0);
            resultInfo.setMsg("用户密码错误");
            return resultInfo;
        }
        resultInfo.setCode(1);
        resultInfo.setResult(user);
        return resultInfo;

    }
}
